#include"TwoStacksImplementationQueue.h"

MyQueue* myQueueCreate()
{
	MyQueue* obj = (MyQueue*)malloc(sizeof(MyQueue));
	StackInit(&obj->pushst);
	StackInit(&obj->popst);
	return obj;
}

void myQueuePush(MyQueue* obj, int x)
{
	StackPush(&obj->pushst, x);
}

int myQueuePeek(MyQueue* obj)
{
	if (IsFull(&obj->popst))
	{
		while (!IsFull(&obj->pushst))
		{
			StackPush(&obj->popst, StackTop(&obj->pushst));
			StackPop(&obj->pushst);
		}
	}
	return StackTop(&obj->popst);
}

int myQueuePop(MyQueue* obj)
{
	int front = myQueuePeek(obj);
	StackPop(&obj->popst);
	return front;
}
bool myQueueEmpty(MyQueue* obj)
{
	return IsFull(&obj->popst) && IsFull(&obj->pushst);
}

void myQueueFree(MyQueue* obj)
{
	StackDestroy(&obj->popst);
	StackDestroy(&obj->pushst);
	free(obj);
}